<?php
import("ORG.Util.Session");
// 本类由系统自动生成，仅供测试用途
class ServiceAction extends Action {

   private function checkLogin(){			//判断是否登陆 否则切到登陆界面
		session_start();
		if($_SESSION['online']==null){
			$this -> redirect('Login/index');
			exit;
		}
		return true;
	}


	public function index(){
		$this->login();
		$model=M('article');
		$cond['type']=$_GET['type'];
		$index=$model->where($cond)->select();
		//dump($index);
		$this->assign('fwjs',$index[0]['content']);
		$this->display();
	}
	public function mod(){
		$cond['type']=$_POST['type'];
		$data=array(
		'content'=>$_POST['content'],
		'pubtime'=>time(),
		'author'=>$_SESSION['online']
		);
		$model=M('article');
		$model->where($cond)->setField($data);
		$this->success('修改成功！');
	}


	public function xlgtzx(){
		$this->login();
		$model=M('c-order');
		$cond['isallowed']=0;
		$cond['type']='心理';
		$cond1['isallowed']=1;
		$cond1['type']='心理';
		$cond2['isallowed']=-1;
		$cond2['type']='心理';
		import("ORG.Util.Page");//导入分页类
		$index=$model->where($cond)->count();
		$index1=$model->where($cond1)->count();
		$index2=$model->where($cond2)->count();
		$Page = new Page($index,30);//实例化分页类传入总记录数和每页显示的记录数
		$Page1 = new Page($index1,30);//实例化分页类传入总记录数和每页显示的记录数
		$Page2 = new Page($index2,30);//实例化分页类传入总记录数和每页显示的记录数
		$show = $Page->show();//分页显示输出
		$show1 = $Page1->show();//分页显示输出
		$show2 = $Page2->show();//分页显示输出
		//进行分页数据查询注意limit方法的参数要使用Page类的属性
		$list = $model->where($cond)->order('id DESC')->limit($Page->firstRow.','.$Page->listRows)->select();
		$list1 = $model->where($cond1)->order('id DESC')->limit($Page1->firstRow.','.$Page1->listRows)->select();
		$list2 = $model->where($cond2)->order('id DESC')->limit($Page2->firstRow.','.$Page2->listRows)->select();
		for($i=0;$i<count($list);$i++){
			$list[$i]['uptime'] = 	date("Y-m-d h:i",$list[$i]['uptime']);
		}
		for($i=0;$i<count($list1);$i++){
			$list1[$i]['uptime'] = 	date("Y-m-d h:i",$list1[$i]['uptime']);
		}
		for($i=0;$i<count($list2);$i++){
			$list2[$i]['uptime'] = 	date("Y-m-d h:i",$list2[$i]['uptime']);
		}
		$this->assign('list',$list);
		$this->assign('list1',$list1);
		$this->assign('list2',$list2);
		$this->assign('page',$show);//赋值分页输出
		$this->assign('page1',$show1);//赋值分页输出
		$this->assign('page2',$show2);//赋值分页输出
		$this->display();
	}
	public function agree(){
		$model=M('c-order');
		$cond['id']=$_GET['id'];
		$model->where($cond)->setField('isallowed',1);
		$this->success('成功！');
	}
	public function discard(){
		$model=M('c-order');
		$cond['id']=$_GET['id'];
		$model->where($cond)->setField('isallowed',-1);
		$this->success('成功！');
	}
	public function deleteorder(){
		$article=M('c-order');
		$id=$_GET[id];
		$cond['id']=$id;
		$article->where($cond)->delete();
		$this->success('删除成功！');
	}

	public function xljiti(){
		$this->login();
		if($_GET['id']==null){
			$this->showjiti();
		}
		else{
			$this->modjiti();
			$this->showjiti();
		}
		$this->display();
	}

	public function jiti(){
		$this->login();
		$model = M('jiti');
        //保存当前数据对象
		$data=array(
			'title'=>$_POST['title'],
			'speaker'=>$_POST['speaker'],
			'time'=>$_POST['time'],
			'place'=>$_POST['place'],
			'content'=>$_POST['content'],
			'ischeck'=>$_POST['ischeck'],
			'type'=>'心理',
			'people'=>$_POST['people'],
			'state'=>$_POST['state']
			);
		if($_POST['id']!=null){
			$cond['id']=$_POST['id'];
			$model->where($cond)->setField($data);
		}
		else{
			$data['id']=$_POST['id'];
			$list = $model->add($data);
		}

		if ($list !== false) {
            $this->success('发布成功！');
        } else {
            $this->error('发布失败!');
        }
	}
	private function showjiti(){
		$model=M('jiti');
		import("ORG.Util.Page");//导入分页类
		$cond['type']='心理';
		$index=$model->where($cond)->count();
		$Page = new Page($index,4);//实例化分页类传入总记录数和每页显示的记录数
		$show = $Page->show();//分页显示输出
		//进行分页数据查询注意limit方法的参数要使用Page类的属性
		$list = $model->where($cond)->order('id DESC')->limit($Page->firstRow.','.$Page->listRows)->select();

		for($i=0;$i<count($list);$i++){
			if($list[$i]['ischeck']==0)
				$list[$i]['ischeck']='否';
			else
				$list[$i]['ischeck']='是';
		}
		$this->assign('list',$list);
		$this->assign('page',$show);//赋值分页输出
	}

	private function modjiti(){
		$cond['id']=$_GET['id'];
		$model=M('jiti');
		$index=$model->where($cond)->select();
		$this->assign('jiti',$index[0]);
	}

	public function deletejiti(){
		$cond['id']=$_GET['id'];
		$model=M('jiti');
		$index=$model->where($cond)->delete();
		$this->success('成功！');
	}


	public function xljtshenhe(){
		$this->login();
		$model=M('h-order');
		$cond['isallowed']=0;
		$cond['type']='心理';
		$cond1['isallowed']=1;
		$cond1['type']='心理';
		$cond2['isallowed']=-1;
		$cond2['type']='心理';
		import("ORG.Util.Page");//导入分页类
		$index=$model->where($cond)->count();
		$index1=$model->where($cond1)->count();
		$index2=$model->where($cond2)->count();
		$Page = new Page($index,10);//实例化分页类传入总记录数和每页显示的记录数
		$Page1 = new Page($index1,10);//实例化分页类传入总记录数和每页显示的记录数
		$Page2 = new Page($index2,10);//实例化分页类传入总记录数和每页显示的记录数
		$show = $Page->show();//分页显示输出
		$show1 = $Page1->show();//分页显示输出
		$show2 = $Page2->show();//分页显示输出
		//进行分页数据查询注意limit方法的参数要使用Page类的属性
		$list = $model->where($cond)->order('id DESC')->limit($Page->firstRow.','.$Page->listRows)->select();
		$list1 = $model->where($cond1)->order('id DESC')->limit($Page1->firstRow.','.$Page1->listRows)->select();
		$list2 = $model->where($cond2)->order('id DESC')->limit($Page2->firstRow.','.$Page2->listRows)->select();
		for($i=0;$i<count($list);$i++){
			$list[$i]['time'] = 	date("Y-m-d h:i",$list[$i]['time']);
		}
		for($i=0;$i<count($list1);$i++){
			$list1[$i]['time'] = 	date("Y-m-d h:i",$list1[$i]['time']);
		}
		for($i=0;$i<count($list2);$i++){
			$list2[$i]['time'] = 	date("Y-m-d h:i",$list2[$i]['time']);
		}
		$this->assign('list',$list);
		$this->assign('list1',$list1);
		$this->assign('list2',$list2);
		$this->assign('page',$show);//赋值分页输出
		$this->assign('page1',$show1);//赋值分页输出
		$this->assign('page2',$show2);//赋值分页输出
		$this->display();
	}
	public function h_agree(){
		$model=M('h-order');
		$cond['id']=$_GET['id'];
		$model->where($cond)->setField('isallowed',1);
		$this->success('成功！');
	}
	public function h_discard(){
		$model=M('h-order');
		$cond['id']=$_GET['id'];
		$model->where($cond)->setField('isallowed',-1);
		$this->success('成功！');
	}
	public function h_deleteorder(){
		$article=M('h-order');
		$id=$_GET[id];
		$cond['id']=$id;
		$article->where($cond)->delete();
		$this->success('删除成功！');
	}
	/*学业--------------*/
	public function xygtzx(){
		$this->login();
		$model=M('c-order');
		$cond['isallowed']=0;
		$cond['type']='心理';
		$cond1['isallowed']=1;
		$cond1['type']='心理';
		$cond2['isallowed']=-1;
		$cond2['type']='心理';
		import("ORG.Util.Page");//导入分页类
		$index=$model->where($cond)->count();
		$index1=$model->where($cond1)->count();
		$index2=$model->where($cond2)->count();
		$Page = new Page($index,30);//实例化分页类传入总记录数和每页显示的记录数
		$Page1 = new Page($index1,30);//实例化分页类传入总记录数和每页显示的记录数
		$Page2 = new Page($index2,30);//实例化分页类传入总记录数和每页显示的记录数
		$show = $Page->show();//分页显示输出
		$show1 = $Page1->show();//分页显示输出
		$show2 = $Page2->show();//分页显示输出
		//进行分页数据查询注意limit方法的参数要使用Page类的属性
		$list = $model->where($cond)->order('id DESC')->limit($Page->firstRow.','.$Page->listRows)->select();
		$list1 = $model->where($cond1)->order('id DESC')->limit($Page1->firstRow.','.$Page1->listRows)->select();
		$list2 = $model->where($cond2)->order('id DESC')->limit($Page2->firstRow.','.$Page2->listRows)->select();
		for($i=0;$i<count($list);$i++){
			$list[$i]['uptime'] = 	date("Y-m-d h:i",$list[$i]['uptime']);
		}
		for($i=0;$i<count($list1);$i++){
			$list1[$i]['uptime'] = 	date("Y-m-d h:i",$list1[$i]['uptime']);
		}
		for($i=0;$i<count($list2);$i++){
			$list2[$i]['uptime'] = 	date("Y-m-d h:i",$list2[$i]['uptime']);
		}
		$this->assign('list',$list);
		$this->assign('list1',$list1);
		$this->assign('list2',$list2);
		$this->assign('page',$show);//赋值分页输出
		$this->assign('page1',$show1);//赋值分页输出
		$this->assign('page2',$show2);//赋值分页输出
		$this->display();
	}

	public function xyjiti(){
		$this->login();
		if($_GET['id']==null){
			$this->showxyjiti();
		}
		else{
			$this->modjiti();
			$this->showxyjiti();
		}
		$this->display();
	}

	public function xueyejiti(){
		$this->login();
		$model = M('jiti');
        //保存当前数据对象
		$data=array(
			'title'=>$_POST['title'],
			'speaker'=>$_POST['speaker'],
			'time'=>$_POST['time'],
			'place'=>$_POST['place'],
			'content'=>$_POST['content'],
			'ischeck'=>$_POST['ischeck'],
			'type'=>'学业',
			'people'=>$_POST['people'],
			'state'=>$_POST['state']
			);
		if($_POST['id']!=null){
			$cond['id']=$_POST['id'];
			$model->where($cond)->setField($data);
		}
		else{
			$data['id']=$_POST['id'];
			$list = $model->add($data);
		}

		if ($list !== false) {
            $this->success('发布成功！');
        } else {
            $this->error('发布失败!');
        }
	}
	private function showxyjiti(){
		$model=M('jiti');
		import("ORG.Util.Page");//导入分页类
		$cond['type']='学业';
		$index=$model->where($cond)->count();
		$Page = new Page($index,4);//实例化分页类传入总记录数和每页显示的记录数
		$show = $Page->show();//分页显示输出
		//进行分页数据查询注意limit方法的参数要使用Page类的属性
		$list = $model->where($cond)->order('id DESC')->limit($Page->firstRow.','.$Page->listRows)->select();

		for($i=0;$i<count($list);$i++){
			if($list[$i]['ischeck']==0)
				$list[$i]['ischeck']='否';
			else
				$list[$i]['ischeck']='是';
		}
		$this->assign('list',$list);
		$this->assign('page',$show);//赋值分页输出
	}




	public function xyjtshenhe(){
		$this->login();
		$model=M('h-order');
		$cond['isallowed']=0;
		$cond['type']='学业';
		$cond1['isallowed']=1;
		$cond1['type']='学业';
		$cond2['isallowed']=-1;
		$cond2['type']='学业';
		import("ORG.Util.Page");//导入分页类
		$index=$model->where($cond)->count();
		$index1=$model->where($cond1)->count();
		$index2=$model->where($cond2)->count();
		$Page = new Page($index,10);//实例化分页类传入总记录数和每页显示的记录数
		$Page1 = new Page($index1,10);//实例化分页类传入总记录数和每页显示的记录数
		$Page2 = new Page($index2,10);//实例化分页类传入总记录数和每页显示的记录数
		$show = $Page->show();//分页显示输出
		$show1 = $Page1->show();//分页显示输出
		$show2 = $Page2->show();//分页显示输出
		//进行分页数据查询注意limit方法的参数要使用Page类的属性
		$list = $model->where($cond)->order('id DESC')->limit($Page->firstRow.','.$Page->listRows)->select();
		$list1 = $model->where($cond1)->order('id DESC')->limit($Page1->firstRow.','.$Page1->listRows)->select();
		$list2 = $model->where($cond2)->order('id DESC')->limit($Page2->firstRow.','.$Page2->listRows)->select();
		for($i=0;$i<count($list);$i++){
			$list[$i]['time'] = 	date("Y-m-d h:i",$list[$i]['time']);
		}
		for($i=0;$i<count($list1);$i++){
			$list1[$i]['time'] = 	date("Y-m-d h:i",$list1[$i]['time']);
		}
		for($i=0;$i<count($list2);$i++){
			$list2[$i]['time'] = 	date("Y-m-d h:i",$list2[$i]['time']);
		}
		$this->assign('list',$list);
		$this->assign('list1',$list1);
		$this->assign('list2',$list2);
		$this->assign('page',$show);//赋值分页输出
		$this->assign('page1',$show1);//赋值分页输出
		$this->assign('page2',$show2);//赋值分页输出
		$this->display();
	}

















	public function zixunreply(){
		$this->login();
		$model=M('consult');
		$cond['isreply']=0;
		import("ORG.Util.Page");//导入分页类
		$index=$model->where($cond)->count();
		$Page = new Page($index,30);//实例化分页类传入总记录数和每页显示的记录数
		$show = $Page->show();//分页显示输出
		//进行分页数据查询注意limit方法的参数要使用Page类的属性
		$list = $model->where($cond)->order('id DESC')->limit($Page->firstRow.','.$Page->listRows)->select();

		for($i=0;$i<count($list);$i++){
			$list[$i]['time'] = 	date("Y-m-d h:i",$list[$i]['time']);
		}
		$this->assign('list',$list);
		$this->assign('page',$show);//赋值分页输出
		$this->display();
	}

	public function reply(){
		$this->login();
		$article=M('consult');
		$id=$_GET[id];
		$cond['id']=$id;
		$list=$article->where($cond)->select();
		$this->assign('list',$list);
		$this->display();
	}
	public function toreply(){
		$this->login();
		$model = M('consult');
        //保存当前数据对象
		$data=array(
			'reply'=>$_POST['content'],
			'isreply'=>1
		);
		$cond['id']=$_POST['id'];
		$list=$model->where($cond)->setField($data);
		if ($list !== false) {
            $this->success('发布成功！');
        } else {
            $this->error('发布失败!');
        }
	}

	public function zixunreplied(){
		$this->login();
		$model=M('consult');
		$cond['isreply']=1;
		import("ORG.Util.Page");//导入分页类
		$index=$model->where($cond)->count();
		$Page = new Page($index,30);//实例化分页类传入总记录数和每页显示的记录数
		$show = $Page->show();//分页显示输出
		//进行分页数据查询注意limit方法的参数要使用Page类的属性
		$list = $model->where($cond)->order('id DESC')->limit($Page->firstRow.','.$Page->listRows)->select();

		for($i=0;$i<count($list);$i++){
			$list[$i]['time'] = 	date("Y-m-d h:i",$list[$i]['time']);
		}
		$this->assign('list',$list);
		$this->assign('page',$show);//赋值分页输出
		$this->display();
	}
	public function delete(){
		$article=M('consult');
		$id=$_GET[id];
		$cond['id']=$id;
		$article->where($cond)->delete();
		$this->success('删除成功！');
	}

	public function liuyanreply(){
		$this->login();
		$model=M('advice');
		$cond['isvisited']=0;
		import("ORG.Util.Page");//导入分页类
		$index=$model->where($cond)->count();
		$Page = new Page($index,30);//实例化分页类传入总记录数和每页显示的记录数
		$show = $Page->show();//分页显示输出
		//进行分页数据查询注意limit方法的参数要使用Page类的属性
		$list = $model->where($cond)->order('id DESC')->limit($Page->firstRow.','.$Page->listRows)->select();

		for($i=0;$i<count($list);$i++){
			$list[$i]['time'] = 	date("Y-m-d h:i",$list[$i]['time']);
		}
		$this->assign('list',$list);
		$this->assign('page',$show);//赋值分页输出
		$this->display();
	}

	public function lyreply(){
		$this->login();
		$article=M('advice');
		$id=$_GET[id];
		$cond['id']=$id;
		$list=$article->where($cond)->select();
		$this->assign('list',$list);
		$this->display();
	}
	public function lytoreply(){
		$this->login();
		$model = M('advice');
        //保存当前数据对象
		$data=array(
			'comment'=>$_POST['content'],
			'isvisited'=>1
		);
		$cond['id']=$_POST['id'];
		$list=$model->where($cond)->setField($data);
		if ($list !== false) {
            $this->success('发布成功！');
        } else {
            $this->error('发布失败!');
        }
	}

	public function liuyanreplied(){
		$this->login();
		$model=M('advice');
		$cond['isvisited']=1;
		import("ORG.Util.Page");//导入分页类
		$index=$model->where($cond)->count();
		$Page = new Page($index,30);//实例化分页类传入总记录数和每页显示的记录数
		$show = $Page->show();//分页显示输出
		//进行分页数据查询注意limit方法的参数要使用Page类的属性
		$list = $model->where($cond)->order('id DESC')->limit($Page->firstRow.','.$Page->listRows)->select();

		for($i=0;$i<count($list);$i++){
			$list[$i]['time'] = 	date("Y-m-d h:i",$list[$i]['time']);
		}
		$this->assign('list',$list);
		$this->assign('page',$show);//赋值分页输出
		$this->display();
	}

	public function lydelete(){
		$article=M('advice');
		$id=$_GET[id];
		$cond['id']=$id;
		$article->where($cond)->delete();
		$this->success('删除成功！');
	}


	public function login(){		//登陆
        $this->	checkLogin();
		$username=$_SESSION['online'];
		if($_SESSION['power']==0){
			$this->assign('username',$username);
			$this->assign('power','超级管理员');
		}
		if($_SESSION['power']==1){
			$this->assign('username',$username);
			$this->assign('power','心理中心');
		}
		if($_SESSION['power']==2){
			$this->assign('username',$username);
			$this->assign('power','学业中心');
		}

    }
	public function logout()
	{
		$this->	checkLogin();
		Session::clear();
		$this->assign('jumpUrl','__APP__');
		$this->assign('waitSecond',2);
		$this->success('退出成功！');
	}
}